<!DOCTYPE html>
<html>

<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, height=device-height, user-scalable=0,  minimum-scale=1, maximum-scale=1">
	<title>地图(御风)</title>
	<link rel="stylesheet" href="../style/map.css">
	<link rel="stylesheet" href="../style/public.css">
</head>

<body>
	<div class="app">
		<div id="map"></div>
    <div class="adr">
      <p>您所在的地址为：</p>
      <p class="adr-text" id="adr"></p>
    </div>
	</div>


	<script src="http://api.map.baidu.com/api?v=2.0&ak=9A2GrD5gEXfF7gFXASYcBI0TQb1D8jSZ"></script>
	<script>
     var map = new BMap.Map('map');
     map.enableScrollWheelZoom(true);
     var point = new BMap.Point(118.667670, 24.714100);
     map.centerAndZoom(point, 16);
    
     map.addControl(new BMap.NavigationControl()); // 平移缩放控件
     map.addControl(new BMap.OverviewMapControl()); // 缩略图控件

     //function myFun(result){
       //var cityName = result.name;
       //map.setCenter(cityName);
		   //alert("当前定位城市:"+cityName);
     //}
	 // var myCity = new BMap.LocalCity();
	 // myCity.get(myFun);

   //var myIcon = new BMap.Icon("http://developer.baidu.com/map/jsdemo/img/fox.gif", new BMap.Size(300,157));
	 //var marker2 = new BMap.Marker(pt,{icon:myIcon});  // 创建标注
	 //map.addOverlay(marker2);              // 将标注添加到地图中

   var geoc = new BMap.Geocoder(); // 创建地址解析器实例
   var text = document.getElementById('adr');
   var geolocation = new BMap.Geolocation();
    geolocation.getCurrentPosition(function(r){
      if(this.getStatus() == BMAP_STATUS_SUCCESS){
        var mk = new BMap.Marker(r.point);
        map.addOverlay(mk);
        map.panTo(r.point);

        var infoWindow = new BMap.InfoWindow();  // 创建信息窗口对象
	      map.openInfoWindow(infoWindow,r.point); //开启信息窗口
        //根据经纬度解析具体地址
        geoc.getLocation(r.point, function(rs){
          var addComp = rs.addressComponents;
          text.innerHTML = addComp.province + addComp.city + addComp.district + addComp.street + addComp.streetNumber;
        });
      }
      else {
        alert('failed'+this.getStatus());
      }        
    },{enableHighAccuracy: true}) 
   </script>
</body>

</html>